package com.lipp.luosu.completablefuture;

import java.util.Random;

/**
 * @ClassNameShop
 * @description: TODO 类描述
 * @Author lipp
 * @Date 2023/11/28 9:46
 * @Version 1.0
 */
public class Shop {
    private  int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    private Random random = new Random();
    /**
     * 根据产品名查找价格
     * */
    public double getPrice(String product) {

        final int a = 1;

        return calculatePrice(product);
    }

    /**
     * 计算价格
     *
     * @param product
     * @return
     * */
    private double calculatePrice(String product) {
        delay();
        //random.nextDouble()随机返回折扣
        return random.nextDouble() * product.charAt(0) + product.charAt(1);
    }

    /**
     * 通过睡眠模拟其他耗时操作
     * */
    private void delay() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        Shop shop = new Shop();
        shop.delay();
     System.out.println(   shop.getPrice("132") );

    }
}
